package com.leo;

import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Tooltip;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.*;
import javafx.scene.paint.Paint;
import javafx.scene.text.Font;
import javafx.stage.Stage;

/**
 * @ClassName TooltipDemo
 * @Description
 * @Author wangss
 * @date 2020.06.01 23:32
 * @Version 1.0
 */
public class Tooltip2Demo extends Application {

    public static void main(String[] args) {
        launch(args);
    }

    @Override
    public void start(Stage primaryStage) throws Exception {
        AnchorPane an = new AnchorPane();
        an.setStyle("-fx-background-color: #e7eeea");
        Scene scene = new Scene(an);

        Tooltip tooltip = new Tooltip();
        tooltip.setFont(new Font(20d));
        tooltip.setPrefWidth(200);
        tooltip.setPrefHeight(200);
        tooltip.setStyle("-fx-background-color: #FFFFFF00");

        VBox vBox = new VBox(10);
        vBox.setPrefWidth(tooltip.getPrefWidth());
        vBox.setPrefHeight(tooltip.getPrefHeight());

        // 设置圆角
        BackgroundFill bf = new BackgroundFill(Paint.valueOf("#ffd8ab"), new CornerRadii(20), new Insets(0));
        Background bg = new Background(bf);
        vBox.setBackground(bg);

        vBox.setAlignment(Pos.CENTER);

        Button button = new Button("button");
        button.setPrefWidth(150d);
        button.setPrefHeight(20d);
        button.setFont(new Font(18));

        Image image = new Image("images/111.jpg");
        ImageView imageView = new ImageView(image);
        imageView.setFitWidth(120d);
        imageView.setFitHeight(120d);

        vBox.getChildren().addAll(button, imageView);

        tooltip.setGraphic(vBox);

        Button b1 = new Button("button1");
        b1.setTooltip(tooltip);

        AnchorPane.setTopAnchor(b1, 100d);
        AnchorPane.setLeftAnchor(b1, 100d);
        an.getChildren().add(b1);
        primaryStage.setScene(scene);
        primaryStage.setTitle("FileChooser");
        primaryStage.setWidth(600d);
        primaryStage.setHeight(600d);
        primaryStage.setResizable(false);
        primaryStage.show();
    }
}
